package com.maimao.goods.client.factory;

import com.maimao.core.enums.RespCode;
import com.maimao.core.model.resp.Result;
import com.maimao.goods.client.ShopClient;
import com.maimao.model.user.Shop;
import com.maimao.model.user.input.ShopBindBrand;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author MaoLin Wang
 * @date 2020/11/30 10:03 下午
 */
@Component
@Slf4j
public class ShopFallBackFactory implements FallbackFactory<ShopClient> {

    @Override
    public ShopClient create(Throwable cause) {
        String errorMsg = cause.getMessage() == null ? "" : cause.getMessage();

        return new ShopClient() {
            @Override
            public Result<Shop> findShopByOwner(Long owner, Integer social) {
                log.error("调用[ShopClient-findShopByOwner({},{})]出错 :{}", owner, social, errorMsg);

                return Result.fail(RespCode.FAIL, errorMsg);
            }


            @Override
            public Result<Shop> queryByIdIn(Long id) {
                log.error("调用[ShopClient-queryById({})]出错 :{}", id, errorMsg);

                return Result.fail(RespCode.FAIL, errorMsg);
            }

            @Override
            public Result<String> queryUserEmailById(Long id) {
                log.error("调用[ShopClient-queryUserEmailById({})]出错 :{}", id, errorMsg);

                return Result.fail(RespCode.FAIL, errorMsg);
            }

            @Override
            public Result<Void> bindBrand(ShopBindBrand shopBindBrand) {
                log.error("调用[ShopClient-bindBrand({})]出错 :{}", shopBindBrand, errorMsg);

                return Result.fail(RespCode.FAIL, errorMsg);
            }

        };
    }
}
